
import com.jme3.bullet.BulletAppState;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Node;
import de.lessvoid.nifty.controls.TextField;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.elements.render.TextRenderer;
import de.lessvoid.nifty.tools.SizeValue;

/**
 *
 * @author 1831139
 */
public class LoadGame {
    public LoadGame(){}
    
    public void setProgress(final float progress, String loadingText) {
        final int MIN_WIDTH = 32;
        int pixelWidth = (int) (MIN_WIDTH + (Main.app.gui.progressBarElement.getParent().getWidth() - MIN_WIDTH) * progress);
        Main.app.gui.progressBarElement.setConstraintWidth(new SizeValue(pixelWidth + "px"));
        Main.app.gui.progressBarElement.getParent().layoutElements();
        Main.app.gui.textRenderer.setText(loadingText);
    }
    
    public void step1(){
        Element element = Main.app.gui.nifty.getScreen("loadlevel").findElementByName("loadingtext");
        Main.app.gui.textRenderer = element.getRenderer(TextRenderer.class);
        Main.app.bullets = new Node("Bullets");
        Main.app.enemies = new Node("Enemies");
        Main.app.playerNode = new Node("Players");
        Main.app.getRootNode().attachChild(Main.app.bullets);
        Main.app.getRootNode().attachChild(Main.app.enemies);
        Main.app.getRootNode().attachChild(Main.app.playerNode);
        ChatMessage join = new ChatMessage("join", "");
        join.setReliable(true);
        Main.app.client.client.send(join);
        setProgress(0.2f, "Loading Nodes");
    }
    
    public void step2(){
        Main.app.bas = new BulletAppState();
        Main.app.bas.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
        Main.app.getStateManager().attach(Main.app.bas);
        Main.app.bas.getPhysicsSpace();
        Main.app.bas.getPhysicsSpace().addCollisionListener(Main.app);
        setProgress(0.4f, "Loading Physics");
    }
    
    public void step3(){
        Main.app.getViewPort().setBackgroundColor(ColorRGBA.Black);
        Main.app.getFlyByCamera().setMoveSpeed(100);
        setProgress(0.5f, "Loading Camera");
    }
    
    public void step4(){
        Main.app.setUpKeys();
        Main.app.setUpLight();
        Main.app.setUpScene();
        setProgress(0.6f, "Creating Scene");
    }
    
    public void step5(){
        Main.app.setUpPlayer();
        setProgress(0.9f, "Loading Player");
    }
    
    public void step6(){
        Main.app.initCannonBall();
        Main.app.initAudio();
        setProgress(0.8f, "Adding Effects");
    }
    
    public void step7(){
        Main.app.setUpEnemy();
        setProgress(1f, "Loading Enemies");
    }
    
    public void step8(){
        Main.app.getInputManager().setCursorVisible(false);
        Main.app.gui.nifty.gotoScreen("end");
        Main.app.gui.nifty.getScreen("end").findNiftyControl("input", TextField.class).disable();
        Main.app.gui.nifty.getCurrentScreen().findElementByName("status").hide();
        Main.app.gui.loaded = 2;
    }
}
